﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Com.Mapabc.Maps.Api.Overlays;
using Com.Mapabc.Maps.Api.BaseTypes;
using Com.Mapabc.Maps.Api;

namespace MapABCAPI_WP7.Samples
{
    /// <summary>
    /// 添加覆盖物示例
    /// </summary>
    public partial class AddOverlayers : PhoneApplicationPage
    {
        public AddOverlayers()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 添加MMarker
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddMarker(object sender, RoutedEventArgs e)
        {
            map.Children.Clear();//清除地图上的所有子容器
            MMarker mk = new MMarker(new MLngLat(116.397945, 39.90817));//构造MMarker
            map.Children.Add(mk);//添加到地图
            map.Center = mk.LngLat;//设置地图中心点
            Pivot.SelectedIndex = 1;//显示效果
        }
        /// <summary>
        /// 添加多折线
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddMPolyline(object sender, GestureEventArgs e)
        {
            map.Children.Clear();//清除地图上的所有子容器
            MLngLatCollection mc = new MLngLatCollection();//构造经纬度序列集合
            mc.Add(new MLngLat(116,39));//集合添加点经纬度坐标
            mc.Add(new MLngLat(116.2, 39.3));//集合添加点经纬度坐标
            mc.Add(new MLngLat(116.12, 39.45));//集合添加点经纬度坐标
            MPolyline ml=new MPolyline();//构造线对象
            ml.LngLats = mc;//mc为组成线的经纬度坐标串
            ml.LineColor = Utilities.HexToColor("#022672") ;//线的颜色
            ml.LineThickness = 3;//线的粗细
            map.Children.Add(ml);//添加到地图
            Pivot.SelectedIndex = 1;//显示效果
           // map.SetFitview(ml);
        }
        /// <summary>
        /// 添加多边形
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddMPologon(object sender, GestureEventArgs e)
        {
            map.Children.Clear();//清除地图上的所有子容器
            MLngLatCollection mp = new MLngLatCollection();//构造经纬度序列集合
            mp.Add(new MLngLat(116.3225715637207,39.909209536859834));//集合添加点经纬度坐标
            mp.Add(new MLngLat(116.3725715637207, 39.95920953685983));//集合添加点经纬度坐标
            mp.Add(new MLngLat(116.42257156372072, 39.95920953685983));//集合添加点经纬度坐标
            MPolygon polygon = new MPolygon();//构造多边形对象
            polygon.LngLats = mp ;//mp为组成多边形的经纬度坐标串
            polygon .FillColor = Utilities.HexToColor("#a3b4ff");//填充颜色
            polygon .FillOpacity =0.8;//填充透明度
            polygon.LineColor = Utilities.HexToColor("#022672");//线的颜色
            polygon.LineThickness = 3;//线的粗细
            map.Children.Add(polygon);//添加到地图
            Pivot.SelectedIndex = 1;//显示效果
        }
        /// <summary>
        /// 添加矩形
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddMRectangle(object sender, GestureEventArgs e)
        {
            map.Children.Clear();//清除地图上的所有子容器
            MLngLatCollection mp = new MLngLatCollection();//构造经纬度序列集合
            mp.Add(new MLngLat(116.3225715637207, 39.909209536859834));//集合添加点经纬度坐标
            mp.Add(new MLngLat(116.3725715637207, 39.95920953685983));//集合添加点经纬度坐标
            MRectangle rectangle = new MRectangle();//构造矩形对象
            rectangle.LngLats = mp;//mp里的前两个坐标为矩形的左上角和右下角坐标
            rectangle.FillColor = Utilities.HexToColor("#a3b4ff");//填充颜色
            rectangle.FillOpacity = 0.8;//填充透明度
            rectangle.LineColor = Utilities.HexToColor("#022672");//线的颜色
            rectangle.LineThickness = 3;//线的粗细
            map.Children.Add(rectangle);//添加到地图
            Pivot.SelectedIndex = 1;//显示效果
        }
        /// <summary>
        /// 添加圆
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddMCircle(object sender, GestureEventArgs e)
        {
            map.Children.Clear();//清除地图上的所有子容器
            MLngLat mc = new MLngLat(116.3225715637207, 39.909209536859834);//构造经纬度坐标
            MCircle circle = new MCircle();//构造圆对象
            circle.SetCenterAndRadius(mc, 1000);//设置圆的中心和半径，半径单位为米
            circle.FillColor = Utilities.HexToColor("#a3b4ff");//填充颜色
            circle.FillOpacity = 0.8;//填充透明度
            circle.LineColor = Utilities.HexToColor("#022672");//线的颜色
            circle.LineThickness = 3;//线的粗细
            map.Children.Add(circle);//添加到地图
            Pivot.SelectedIndex = 1;//显示效果
        }

        /// <summary>
        /// 重写后退键
        /// </summary>
        /// <param name="e"></param>
        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (Pivot.SelectedIndex==1)
            {
                e.Cancel = true;
                Pivot.SelectedIndex = 0;
            }
        }
    }
}